package cn.xshi.sys.service.impl;
import java.util.List;
import java.util.Map;

import cn.xshi.sys.init.GlobalPersistentComponent;
import cn.xshi.sys.model.SysPath;
import cn.xshi.sys.service.SysPathService;
import cn.xshi.sys.dao.SysPathDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.xshi.common.base.BaseService;
import cn.xshi.common.util.ExceptionUtil;
import javax.annotation.Resource;
/**
 * @Desc 文件路径
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@Service
@Slf4j
public class SysPathServiceImpl extends BaseService implements SysPathService {

	@Resource
	private SysPathDao sysPathDao;

	@Resource
    GlobalPersistentComponent globalPersistentComponent;

	/**
	* 分页
	* @param condition 
	* @return
	*/
	public List<SysPath> getSysPathListByCondition(Map<String,Object> condition){
		try {
			return sysPathDao.getSysPathListByCondition(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}

	/**
	* 查询对象
	* @param id
	* @return
	*/
	public SysPath getSysPathById(String id){
		try {
			return sysPathDao.getSysPathById(id);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}

	/**
	* 添加
	* @param sysPath
	* @return
	*/
	public int addSysPath(SysPath sysPath){
		int i = 0;
		try {
			sysPath.setCreateId(getCurrentAccountId());
			sysPath.setCreateTime(getDate());
			i = sysPathDao.addSysPath(sysPath);
			globalPersistentComponent.initPath();
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	* 修改
	* @param sysPath
	* @return
	*/
	public int updateSysPath(SysPath sysPath){
		int i = 0;
		try {
			sysPath.setUpdateId(getCurrentAccountId());
			sysPath.setUpdateTime(getDate());
			i = sysPathDao.updateSysPath(sysPath);
			globalPersistentComponent.initPath();
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	* 删除
	* @param condition 
	* @return
	*/
	public int delSysPath(Map<String,Object> condition){
		int i = 0;
		try {
			i = sysPathDao.delSysPath(condition);
			globalPersistentComponent.initPath();
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 查找所有平台路径
	 * @param condition
	 * @return
	 */
	public List<SysPath> getSysPathListAllByCondition(Map<String,Object> condition){
		try {
			return sysPathDao.getSysPathListAllByCondition(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}
}
